#coding=utf-8

import os
import configparser as conf

class DBConnectionInfo(object):
	#定义数据字典
	Connections = {}
	
	
	#写库信息
	cf = conf.ConfigParser()
	cf.read('/usr/local/azkaban/db_conf/UCAR_DA.conf',encoding='utf-8' )

	
	
	def __init__(self):
		pass
		
		
	@staticmethod
	def init():
		#DBConnectionInfo.Connections['BI_ODS'] = DBConnectionInfo.parseConnectionInfo('BI_ODS')
		#DBConnectionInfo.Connections['BI_ODS_READONLY'] = DBConnectionInfo.parseConnectionInfo('BI_ODS_READ')
		DBConnectionInfo.Connections['BI_DM'] = DBConnectionInfo.parseConnectionInfo('BI_DM')
		#DBConnectionInfo.Connections['BI_DM_ZC'] = DBConnectionInfo.parseConnectionInfo('BI_DM_ZC')
		#DBConnectionInfo.Connections['BI_DM_READONLY'] = DBConnectionInfo.parseConnectionInfo('BI_DM_READ')
		#DBConnectionInfo.Connections['BI_DW'] = DBConnectionInfo.parseConnectionInfo('BI_DW')
		#DBConnectionInfo.Connections['BI_DW_READONLY'] = DBConnectionInfo.parseConnectionInfo('BI_DW_READ')
		#DBConnectionInfo.Connections['BI_COMMON'] = DBConnectionInfo.parseConnectionInfo('BI_COMMON')
		#DBConnectionInfo.Connections['BI_COMMON_READONLY'] = DBConnectionInfo.parseConnectionInfo('BI_COMMON_READ')
		#DBConnectionInfo.Connections['BI_DM_MMC'] = DBConnectionInfo.parseConnectionInfo('BI_DM_MMC')
		
		'''
		DBConnectionInfo.Connections['BI_ODS'] = {'database':'BI_ODS','user':'bi_ucar','password':'BI_ucar2015','server':'10.104.20.40'}
		DBConnectionInfo.Connections['BI_DM'] = {'database':'BI_DM','user':'bi_ucar','password':'BI_ucar2015','server':'10.104.20.40'}
		DBConnectionInfo.Connections['BI_DW'] = {'database':'BI_DW','user':'bi_ucar','password':'BI_ucar2015','server':'10.104.20.40'}
		DBConnectionInfo.Connections['BI_COMMON'] = {'database':'BI_COMMON','user':'bi_ucar','password':'BI_ucar2015','server':'10.104.20.40'}
		'''
	@staticmethod
	def parseConnectionInfo_BI_ODS():
		#TODO:通过环境变量读取连接,存储至Connections,例如:Data Source=10.101.23.40,1433;User ID=bi_ucar;Initial Catalog=BI_USER_STAGE;Provider=SQLNCLI11.1;
		'''
		#解析翻译成字典的存放方式
		conn
		Connections['BI_ODS'] = getenv('BI_ODS_CON_STR')
		
		'''
		return ""
		pass
	#Windows的方式
	@staticmethod
	def parseEnvConnValueStr2Dic(envName):
		connInfo = {}
		connStr = getenv(envName)
		conArr = connStr.split(';')
		#TODO: 将conArr进一步使用=号来分隔，放到字典里
		
	@staticmethod	
	def parseConnectionInfo(section_name):

		conn = {}
		conn['database'] = DBConnectionInfo.cf.get(section_name,'db')
		conn['user'] = DBConnectionInfo.cf.get(section_name,'user')
		conn['password'] = DBConnectionInfo.cf.get(section_name,'password')
		conn['server'] = DBConnectionInfo.cf.get(section_name,'host')
		conn['port'] = DBConnectionInfo.cf.get(section_name,'port')
		conn['charset'] = DBConnectionInfo.cf.get(section_name,'charset')
		return conn
		
		
DBConnectionInfo.init()	
